package chances.epg.data.taglib;

import javax.servlet.jsp.JspException;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;

import chances.epg.commons.log.EpgLogFactory;
import chances.epg.entity.content.Category;


public class CategoryTag extends QueryTag {
	private static final Logger logger = EpgLogFactory.getSystemLogger();
	
	/**
	 * serialVersionUID.
	 */
	private static final long serialVersionUID = 540651386268088709L;
	private String code;
	
	@Override
	public int doEndTag() throws JspException {
		String catCode = this.getCode();
		if(StringUtils.isBlank(catCode)){
			catCode = this.getCurCategoryCode();
		}
		
		if(StringUtils.isBlank(catCode)){
			logger.debug("catCode and curCatCode is null.");
		}
		
		try{
			if(StringUtils.isNotBlank(catCode)){
				Category category = this.getContentService().getCategoryByCode(catCode);
				this.setResult(category);
			}
		}catch(Throwable ex){
			logger.error("CategoryTag error",ex);
		}
		
		return super.doEndTag();
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
}
